<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { getHomePage } from '@/api'

const activeName = ref(null)

// banner
const bannerDetail = ref({})
// tabs 数据
const pageDetail = ref({})
const getPageData = async () => {
  const data = await getHomePage()
  pageDetail.value = data?.tab_contents || []
  activeName.value = data?.tab_contents?.tabs[0] || ''
  bannerDetail.value = data?.carousel?.items || []
}

onMounted(() => {
  getPageData()
})
</script>

<template>
  <div class="layout-container bg-white">
    <el-carousel v-if="bannerDetail" height="300px">
      <el-carousel-item v-for="item in bannerDetail" :key="item.id">
        <a v-if="item.link" :href="item.link">
          <el-image
            class="w-full h-full bg-white overflow-hidden"
            :src="item.image"
            fit="contain"
          />
        </a>
        <el-image
          v-else
          class="w-full h-full bg-white overflow-hidden"
          :src="item.image"
          fit="contain"
        />
      </el-carousel-item>
    </el-carousel>
    <div style="margin-top: 50px">
      <el-tabs v-model="activeName" type="card" class="demo-tabs">
        <el-tab-pane v-for="(item, index) in pageDetail.tabs" :label="item" :name="item">
          <div class="posts">
            <div class="posts-content" v-html="pageDetail?.contents[index]"></div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.posts {
  padding: 30px;

  .posts-content {
    img {
      width: 100% !important;
    }
  }
}
</style>
